#!/usr/bin/make -f
# -*- makefile -*-

# StaffLog Services - Predesys services
# Version: 0.1
# Authors: Jose A. Jimenez <jajimc@gmail.com>, Miguel Centeno <miguelcent@gmail.com>
# License: GPL 3.0 (see "license" file)

DEST_MAINDIR 	= /usr/share/predesys-server/services

SRC_MAINDIR		= src

compile:

install:	basic-install

basic-install:
	# Directories creation
	mkdir -p $(DEST_MAINDIR)
	
	# Program files installation
	install -p -m 0644 $(SRC_MAINDIR)/stafflog_setup.py $(DEST_MAINDIR)
	install -p -m 0644 $(SRC_MAINDIR)/stafflog_checkin.py $(DEST_MAINDIR)
	
	# Add user for "stafflog_checkin" service
	predesys-server users add -id stafflog_checkin -gid client -e 1
	predesys-server users changep -user stafflog_checkin -passwd stafflog_checkin
	
	# Add services to Predesys Server
	predesys-server services add -id stafflog_setup -v "0.1" -tid "callable-system" -a 1 -e 1 -p stafflog_setup.py -name "Stafflog Setup" -author "Jose A. Jimenez <jajimc@gmail.com>, Miguel Centeno <miguelcent@gmail.com>"
	predesys-server services add -id stafflog_checkin -v "0.1" -tid "callable-system" -a 0 -e 1 -p stafflog_checkin.py -name "Stafflog Checkin" -author "Jose A. Jimenez <jajimc@gmail.com>, Miguel Centeno <miguelcent@gmail.com>"
	
	# Add service permissions to Predesys Server
	predesys-server serviceperms add -sid stafflog_setup -gid client
	predesys-server serviceperms add -sid stafflog_checkin -gid client

	# Import SQL tables to Predesys Server DB
	python install_db.py

uninstall:
	# Remove user
	predesys-server users del -f stafflog_checkin
	
	# Remove services from Predesys Server
	predesys-server services del -f stafflog_setup
	predesys-server services del -f stafflog_checkin
	
	# Program files deletion
	rm $(DEST_MAINDIR)/stafflog_setup.py
	rm $(DEST_MAINDIR)/stafflog_checkin.py
	
	# Delete SQL tables from Predesys Server DB
	python uninstall_db.py
